

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>任务信息编辑</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
</head>

<body>

  <form class="layui-form" lay-filter="layuiadmin-app-form-list" 
  id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
  
  
    <div class="layui-form-item">
      <label class="layui-form-label">授权码</label>
      <div class="layui-input-block">
        <input type="text" name="code" 
		lay-verify="required"  disabled = disabled  class="layui-input">
      </div>
    </div>

	
	<div class="layui-form-item">
	  <label class="layui-form-label">授权码说明</label>
	  <div class="layui-input-block">
	    <input type="text" name="note" lay-verify="required" 
		placeholder="请输入授权码说明" autocomplete="off" class="layui-input">
	  </div>
	</div>
	
	<div class="layui-form-item">
		    <label class="layui-form-label">授权码类型</label>
		    <div class="layui-input-block">
		      <select name="codeType" lay-filter="codeType">
		        <option value=""></option>
				 <option value="0" >永不过期</option>
				<option value="1" selected="">时间设置</option>
		       
		      </select>
		    </div>
		 </div>
		 
		 
	<div class="layui-inline">
	      <label class="layui-form-label">有效日期</label>
	      <div class="layui-input-inline">
	        <input type="text" class="layui-input" 
			id="expiretime"  name ="expiretime"  lay-filter="expiretime" placeholder="yyyy-MM-dd">
	      </div>
	 </div>
	

	<div class="layui-form-item">
	  <div class="layui-input-inline">
	    <input type="hidden" name="id"    class="layui-input">
	  </div>
	</div>
	

    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
  </form>
  
  <script src="../../layuiadmin/layui/layui.js"></script> 
  <script src="../../../js/common.js"></script>
  <script src="../../../js/TimeUtils.js"></script>
  <script src="../../../lib/jquery-3.3.1.min.js"></script>
  <script>
	  
  var _form;
  var setter;
  layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form','laydate'], function(){
    var $ = layui.$
    ,form = layui.form;
	setter = layui.setter;
	_form = form;
	var laydate = layui.laydate;

   laydate.render({
      elem: '#expiretime'
    });
	
	var ID = GetQueryVariable("id");
	if(ID!=false)
	{
		var url = setter.prefixUrl+"SearchCodeById/"+ID;
		$.post(url, function(data){
			
			  form.val("layuiadmin-app-form-list", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
				"code": RemoveSpace(data.code) // "name": "value"
				,"id": data.id
				,"note": data.note
				,"codeType":data.codeType
				,"expiretime":formatServerDateTime(data.expiretime,'yyyy-MM-dd')
			  });
			  
			  if(data.codeType==0)
			  {
				  $("#expiretime").attr({"disabled":"disabled"});
			  }
			  else{
				   
				   //alert(formatServerDateTime(data.expiretime,'yyyy-MM-dd'));
			  }
			  
			  
		});
	}
	else
	{
		var url = setter.prefixUrl+"GetRandomActiveCode";
		$.post(url, function(data){
			
			
			  form.val("layuiadmin-app-form-list", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
				"code": data // "name": "value"
			  });
		});
	}
	
	form.on('select(codeType)', function(data){
			
			//设置日期
			if(data.value==1)
			{
				$("#expiretime").removeAttr("disabled");
				
			}else
			{
				$("#expiretime").attr({"disabled":"disabled"});
			}
			taskTypeSelect = data.value;
			
		});
		
		
    //监听提交，Add
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      //提交 Ajax 成功后，关闭当前弹层并重载表格
	   var _expiretime = $("#expiretime").val();
	   var code = field.code;
	   var codeType = field.codeType;
	   var note = field.note;
	   
	  
	  if(codeType == 0 || _expiretime=="")
	  {
		  _expiretime = 0;
	  }
	  var url = setter.prefixUrl+"AddCode/"+code+"/"+codeType+ "/"+note + "/"+_expiretime;
	  $.get(url, field,
	         function(data){
			 if(data==0)
			 {
				 layer.alert("操作成功"); 
				 parent.layui.table.reload('LAY-app-content-list'); //重载表格
				 parent.layer.close(index); //再执行关闭 
			 }
			 else
			 {
				 layer.alert(data.msg); 
				 return false;
			 }
	         
	   });
		
    });
	

  })
  
  </script>
</body>
</html>